package com.atguigu.exam.mapper;


import com.atguigu.exam.entity.Question;
import com.atguigu.exam.vo.QuestionPageVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 题目Mapper接口
 * 继承MyBatis Plus的BaseMapper，提供基础的CRUD操作
 */
public interface QuestionMapper extends BaseMapper<Question> {
    //查询所有分类和分类对应的题目数量
    @Select("SELECT category_id,COUNT(*) ct from questions where is_deleted=0 GROUP BY category_id")
    List<Map<Long, Long>> selectCategoryAndCount();

    /**
     * 查询题目和对应的答案
     *
     * @param pageBean
     * @param questionPageVo
     * @return
     */
    IPage<Question> selectQuestionAndAnswer(IPage<Question> pageBean, @Param("vo") QuestionPageVo questionPageVo);

    Question selectQuestionById(Long id);
}